# coding=utf-8
# 全世界最帅的帅哥
# https://leetcode.cn/problems/UHnkqh/


# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        prev = None
        next_ = None
        # 思路
        # a -> b -> c
        # next, prev = None, None
        # next 指向 head.next
        # head.next 指向prev
        # prev 指向 head
        # head 指向 next
        while head:
            next_ = head.next
            head.next = prev
            prev = head
            head = next_
        return prev
